#include "Texture.h"
Texture::Texture(void)
{
	titling = 1;
}

Texture::~Texture(void)
{
}
void Texture::Init(char* fname){
	int bpp;
	glGenBuffers(1,&textureId);
	glBindTexture(GL_TEXTURE_2D,textureId);
	char* imgData = LoadTGA(fname,&tWidth,&tHeight,&bpp);

	if(bpp == 24){
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tWidth, tHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, imgData);
	}else{
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tWidth, tHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData);
	}
	SAFE_DEL(imgData);
	if(titling == 1){
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
	}
	if(titling == 2){
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	}
	glGenerateMipmap(GL_TEXTURE_2D);
}
void Texture::SetTitling(unsigned char i){
	if(titling == 1){
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
	}
	if(titling == 2){
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	}
}

int Texture::GetHeight(){
	return tHeight;
}
int Texture::GetWidth(){
	return tWidth;
}
GLuint Texture::GetTextureId(){
	return textureId;
}